package com.one.shopping.ui.fragment;

import android.widget.Toast;

import com.one.shopping.R;
import com.one.shopping.adapter.CommonAdapter;
import com.one.shopping.adapter.GoodsAdapter;
import com.one.shopping.api.OneApi;
import com.one.shopping.entity.Goods;
import com.one.shopping.entity.Result;
import com.one.shopping.ui.baseFragment.BaseSwipeRefreshFragment;
import com.one.shopping.util.GsonUtils;

import java.util.List;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/8 17:55
 */
public class ShopItemFragment extends BaseSwipeRefreshFragment<Goods> {



    @Override
    public CommonAdapter<Goods> getAdapter() {
        return new GoodsAdapter(getActivity(), R.layout.list_item_goods);
    }

    @Override
    public List<Goods> getDatas(byte[] responeString) {
        Result result = GsonUtils.fromJson(new String(responeString), Result.class);
        List<Goods> goodses = GsonUtils.json2List(result.getData(), Goods.class);
        return goodses;
    }

    @Override
    public void requestData() {
        OneApi.getGoodsList(mHandler);
    }

    @Override
    public void onItemClick(int position, Goods goods) {
        Toast.makeText(getActivity(), goods.getName(), Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onItemLongClick(int position, Goods data) {

    }
}
